package logic

import (
	"context"
	"errors"
	"gitignore/gitignorerpc/gitignorerpc"
	"gitignore/gitignorerpc/internal/svc"
	"gitignore/models/mysql"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentAddLogic) CommentAdd(in *gitignorerpc.CommentAddRequest) (*gitignorerpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line

	comment := mysql.Comment{
		//Model:          gorm.Model{},
		VideoId:        int(in.VideoId),
		UserId:         int(in.UserId),
		CommentContent: in.CommentContent,
	}
	if strings.Contains(in.CommentContent, "骗人") || strings.Contains(in.CommentContent, "垃圾") {
		return nil, errors.New("包含违规词汇，请修改后提交")
	}
	err := comment.FindCommentByAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("评论失败")
	}

	return &gitignorerpc.CommentAddResponse{
		CommentId: int64(comment.ID),
	}, nil
}
